//
//  DoctorViewController.m
//  QuickCure
//
//  Created by 曹魏 on 16/9/15.
//  Copyright © 2016年 haoge. All rights reserved.
//

/**
 *doctor_portrait;
 *doctor_name;
 *doctor_title_name;
 *doctor_hospital_name;
 *accuracy;
 *operation_count;
 *flower;
 *banner;
 */

#import "DoctorListCell.h"
#import <UIImageView+WebCache.h>

@interface DoctorListCell()

@property (nonatomic,weak)UIImageView *portraitImageView;
@property (nonatomic,weak)UILabel *nameLabel;
@property (nonatomic,weak)UILabel *titleNameLabel;
@property (nonatomic,weak)UILabel *hosptNameLabel;
@property (nonatomic,weak)UIButton *accuracyBtn;
@property (nonatomic,weak)UIButton *operation_countBtn;
@property (nonatomic,weak)UIButton *flowerBtn;
@property (nonatomic,weak)UIButton *bannerBtn;


@end

@implementation DoctorListCell

//懒加载子控件:
- (UIImageView *)portraitImageView
{
    if(!_portraitImageView)
    {
        UIImageView *imageView = [[UIImageView alloc]init];
        _portraitImageView = imageView;
        [self.contentView addSubview:imageView];
        
    }
    return _portraitImageView;
}
- (UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        UILabel *label = [[UILabel alloc]init];
        _nameLabel = label;
        [self.contentView addSubview:label];
    }
    return _nameLabel;
}
- (UILabel *)titleNameLabel
{
    if(!_titleNameLabel)
    {
        UILabel *label = [[UILabel alloc]init];
        _titleNameLabel = label;
        [self.contentView addSubview:label];
        [label setTextColor:[UIColor colorWithWhite:0.7 alpha:1]];
    }
    return _titleNameLabel;
}
- (UILabel *)hosptNameLabel
{
    if(!_hosptNameLabel)
    {
        UILabel *label = [[UILabel alloc]init];
        _hosptNameLabel = label;
        [self.contentView addSubview:label];
        [label setTextColor:[UIColor colorWithWhite:0.7 alpha:1]];

    }
    return _hosptNameLabel;
}
- (UIButton *)accuracyBtn
{
    if(!_accuracyBtn)
    {
        UIButton *btn = [[UIButton alloc]init];
        _accuracyBtn = btn;
        [self.contentView addSubview:btn];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"pipeidu"] forState:UIControlStateNormal];
    }
    return _accuracyBtn;
}
- (UIButton *)operation_countBtn
{
    if(!_operation_countBtn)
    {
        UIButton *btn = [[UIButton alloc]init];
        _operation_countBtn = btn;
        [self.contentView addSubview:btn];
        
        [btn setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRed:0.374 green:0.792 blue:0.933 alpha:1.000] forState:UIControlStateNormal];
    }
    return _operation_countBtn;
}
- (UIButton *)flowerBtn
{
    if(!_flowerBtn)
    {
        UIButton *btn = [[UIButton alloc]init];
        _flowerBtn = btn;
        [self.contentView addSubview:btn];
        [btn setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRed:0.374 green:0.792 blue:0.933 alpha:1.000] forState:UIControlStateNormal];

    }
    return _flowerBtn;
}
- (UIButton *)bannerBtn
{
    if(!_bannerBtn)
    {
        UIButton *btn = [[UIButton alloc]init];
        _bannerBtn = btn;
        [self.contentView addSubview:btn];
        [btn setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithRed:0.118 green:0.789 blue:0.805 alpha:1.000] forState:UIControlStateNormal];

    }
    return _bannerBtn;
}


#pragma mark -----以上都是懒加载-----:


//初始化:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setup];
    }
    return self;
}

- (void)setup
{
    //灰边:
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    [self.contentView addSubview:grayView];
    [grayView setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1]];
    
    //头像:
    [self.portraitImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@80);
        make.top.equalTo(self.contentView).offset(30);
        make.leading.equalTo(self.contentView).offset(20);
    }];
    //头像裁圆形:
    self.portraitImageView.layer.cornerRadius = 40;
    self.portraitImageView.clipsToBounds = YES;
    
    //名字:
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.portraitImageView.mas_trailing).offset(10);
        make.top.equalTo(self.contentView).offset(30);
    }];
    
    //职称:
    [self.titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.portraitImageView.mas_trailing).offset(70);
        make.top.equalTo(self.contentView).offset(30);
    }];
    
    //医院名:
    [self.hosptNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.portraitImageView.mas_trailing).offset(10);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10);
    }];
    

    //手术次数:
    [self.operation_countBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@50);
        make.height.equalTo(@20);
        make.leading.equalTo(self.portraitImageView.mas_trailing).offset(10);
        make.top.equalTo(self.hosptNameLabel.mas_bottom).offset(10);
    }];
    
    //💐数量:
    [self.flowerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@50);
        make.height.equalTo(@20);
        make.leading.equalTo(self.operation_countBtn.mas_trailing);
        make.top.equalTo(self.hosptNameLabel.mas_bottom).offset(10);
    }];
    
    //锦旗数量:
    [self.bannerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@50);
        make.height.equalTo(@20);
        make.leading.equalTo(self.flowerBtn.mas_trailing);
        make.top.equalTo(self.hosptNameLabel.mas_bottom).offset(10);
    }];

    //匹配度:
    [self.accuracyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@50);
        make.height.equalTo(@60);
        make.top.equalTo(self.contentView).offset(15);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-20);
    }];
    [self.accuracyBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    self.accuracyBtn.titleLabel.numberOfLines = 2;
    [self.accuracyBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
}

#pragma mark
#pragma mark 设置数据:
- (void)setModel:(AttentionDoctorModel *)model
{
    _model = model;
    
    [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"]];
    
    self.nameLabel.text = model.doctor_name;
    self.titleNameLabel.text = model.doctor_title_name;
    self.hosptNameLabel.text = model.doctor_hospital_name;
    
    [self.accuracyBtn setTitle:[NSString stringWithFormat:@"匹配度%@",model.accuracy] forState:UIControlStateNormal];


    [self.operation_countBtn setTitle:[NSString stringWithFormat:@"  %@", model.operation_count] forState:UIControlStateNormal];
    [self.flowerBtn setTitle:[NSString stringWithFormat:@"  %@", model.flower] forState:UIControlStateNormal];
    [self.bannerBtn setTitle:[NSString stringWithFormat:@"  %@", model.banner] forState:UIControlStateNormal];
    
    
}

@end










